package unclassified.medium;

public class MinimumNumberOfBucketsRequiredToCollectRainwaterFromHouses_5923 {

    public int minimumBuckets(String street) {
        if ("H".equals(street) || street.startsWith("HH") || street.endsWith("HH") || street.contains("HHH")) {
            return -1;
        }

        int ans = 0;
        for (int i = 0; i < street.length(); i++) {
            if (street.charAt(i) == 'H') {
                ans++;
            }
        }
        for (int i = 0; i < street.length() - 2; i++) {
            if (street.charAt(i) == 'H' && street.charAt(i + 1) == '.' && street.charAt(i + 2) == 'H'){
                ans--;
                i+=2;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        MinimumNumberOfBucketsRequiredToCollectRainwaterFromHouses_5923 mn = new MinimumNumberOfBucketsRequiredToCollectRainwaterFromHouses_5923();
        System.out.println(mn.minimumBuckets("HHHH..."));
    }
}
